package info.niwota.web.proxy;

import java.io.InputStream;

import jvs.peer.util.Log;
import x.org.apache.http.impl.io.SocketOutputBuffer;

public class CopyOutThread extends Thread {

	private InputStream in;
	private SocketOutputBuffer out;

	public CopyOutThread(InputStream in, SocketOutputBuffer out) {
		this.in = in;
		this.out = out;
	}

	public void run() {
		try {
			byte[] buf = new byte[1024];
			int len;
			while (true) {
				len = in.read(buf);

				if (Log.TRACE) {
					Log.v("<< CopyOutThread ",
							Thread.currentThread() + " >> len: " + len);
				}
				
				if (len == -1) {
					break;
				}
				if (len > 0) {
					out.write(buf, 0, len);
					out.flush();
				}
			}

		} catch (Exception e) {	
			if (Log.DEBUG) {
				Log.d("<< CopyOutThread ", e + "");
			}
		} finally {
			try {
				in.close();
			} catch (Exception e) {
				e.printStackTrace();
			}
		}

	}
}
